﻿using Comsenz.Discuz.Configs;
using System.Web;

namespace Comsenz.Discuz
{
    /// <summary>
    /// 资源链接助理
    /// </summary>
    /// <author>Chiron</author>
    public static class DiscuzUri
    {
        private readonly static DiscuzConfig Config = DiscuzConfig.Instance;
        #region Props
        /// <summary>
        /// Discuz用户登录地址
        /// </summary>
        public static string LoginUri
        {
            get
            {
                return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + "member.php?mod=logging&action=login";
            }
        }

        /// <summary>
        /// Discuz用户注销登录地址
        /// </summary>
        public static string LogoutUri
        {
            get
            {
                return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + "member.php?mod=logging&action=logout";
            }
        }

        /// <summary>
        /// Discuz用户注册地址
        /// </summary>
        public static string RegisterUri
        {
            get
            {
                return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + "member.php?mod=register";
            }
        }

        /// <summary>
        /// Discuz更新资料地址
        /// </summary>
        public static string ProfileUri
        {
            get
            {
                return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + "home.php?mod=spacecp&ac=profile";
            }
        }

        /// <summary>
        /// Discuz查看留言地址
        /// </summary>
        public static string WallUri
        {
            get
            {
                return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + "home.php?mod=space&do=wall";
            }
        }

        /// <summary>
        /// Discuz编辑头像地址
        /// </summary>
        public static string AvatarUri
        {
            get
            {
                return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + "home.php?mod=spacecp&ac=avatar";
            }
        }
        #endregion Props

        #region Methods

        #region 门户
        /// <summary>
        /// 取得门户专题页地址
        /// </summary>
        /// <param name="name">专题名</param>
        /// <returns></returns>
        public static string GetPortalTopicsUri(string name)
        {
            return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + string.Format("portal.php?mod=topic&topic={0}", name);
        }

        /// <summary>
        /// 取得门户文章页地址
        /// </summary>
        /// <param name="id">文章ID</param>
        /// <param name="page">页码</param>
        /// <returns></returns>
        public static string GetPortalNewsUri(int id, int? page = null)
        {
            return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + string.Format("portal.php?mod=view&aid={0}{1}", id, page.HasValue ? "&page=" + page : "");
        }
        #endregion 门户

        #region 论坛
        /// <summary>
        /// 取得论坛主题列表页地址
        /// </summary>
        /// <param name="fid">主题ID</param>
        /// <param name="page">页码</param>
        /// <returns></returns>
        public static string GetForumTopicsUri(int fid, int? page = null)
        {
            return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + string.Format("forum.php?mod=forumdisplay&fid={0}{1}", fid, page.HasValue ? "&page=" + page : "");
        }

        /// <summary>
        /// 取得论坛主题内容页地址
        /// </summary>
        /// <param name="tid">帖子ID</param>
        /// <param name="page">页码</param>
        /// <param name="prevpage"></param>
        /// <returns></returns>
        public static string GetForumThreadUri(int tid, int? page = null, string prevpage = null)
        {
            return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + string.Format("forum.php?mod=viewthread&tid={0}{1}{2}", tid, page.HasValue ? "&page=" + page : "", string.IsNullOrEmpty(prevpage) ? "" : "&extra=page" + prevpage);
        }

        /// <summary>
        /// 取得群组主题列表页地址
        /// </summary>
        /// <param name="fid">主题ID</param>
        /// <param name="page">页码</param>
        /// <returns></returns>
        public static string GetForumGroupsUri(int fid, int? page = null)
        {
            return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + string.Format("forum.php?mod=group&fid={0}{1}", fid, page.HasValue ? "&page=" + page : "");
        }

        /// <summary>
        /// 论坛 Archiver 页
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="action">操作类型(fid|tid)默认为fid</param>
        /// <returns></returns>
        public static string GetForumArchiverUri(string value, string action = "fid")
        {
            return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + string.Format("index.php?action={0}&value={1}", action, value);
        }
        #endregion 论坛

        #region 个人主页
        /// <summary>
        /// 取得用户个人主页地址
        /// </summary>
        /// <param name="username">用户名</param>
        /// <returns></returns>
        public static string GetUHomeUri(string username)
        {
            return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + string.Format("home.php?mod=space&view=admin&username={0}", username);
        }

        /// <summary>
        /// 取得用户个人主页地址
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <returns></returns>
        public static string GetUHomeUri(int uid)
        {
            return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + string.Format("home.php?mod=space&view=admin&uid={0}", uid);
        }
        #endregion 个人主页

        #region 交互
        /// <summary>
        /// 添加指定用户为好友的地址
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="handlekey"></param>
        /// <returns></returns>
        public static string GetAddFriendUri(int uid, string handlekey = null)
        {
            return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + string.Format("home.php?mod=spacecp&ac=friend&op=add&uid={0}{1}", uid, string.IsNullOrEmpty(handlekey) ? "" : "&handlekey=" + handlekey);
        }
        /// <summary>
        /// 给指定用户留言的地址
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <returns></returns>
        public static string GetPostToWallUri(int uid)
        {
            return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + string.Format("home.php?mod=space&do=wall&uid={0}", uid);
        }
        /// <summary>
        /// 对指定用户打招呼的地址
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="handlekey"></param>
        /// <returns></returns>
        public static string GetSendPokeUri(int uid, string handlekey = null)
        {
            return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + string.Format("home.php?mod=spacecp&ac=poke&op=send&uid={0}{1}", uid, string.IsNullOrEmpty(handlekey) ? "" : "&handlekey=" + handlekey);
        }
        /// <summary>
        /// 发送消息给指定用户的地址
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="handlekey"></param>
        /// <returns></returns>
        public static string GetSendMessageUri(int uid, string handlekey = null)
        {
            return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + string.Format("home.php?mod=spacecp&ac=pm&op=showmsg&pmid=0&daterange=2&touid={0}{1}", uid, string.IsNullOrEmpty(handlekey) ? "" : "&handlekey=" + handlekey);
        }
        #endregion 交互

        /// <summary>
        /// 取得用户日志内容页地址
        /// </summary>
        /// <param name="uid">用户ID</param>
        /// <param name="blogid">日志ID</param>
        /// <returns></returns>
        public static string GetBlogUri(int uid, int? blogid = null)
        {
            return VirtualPathUtility.AppendTrailingSlash(Config.CurrentConnectConfig.DiscuzUri) + string.Format("home.php?mod=space&do=blog&uid={0}{1}", uid, blogid.HasValue ? "&id=" + blogid : "");
        }
        #endregion Methods

    }
}
